# ==============================================================================#
#    Amrita ITEWS - Copyright (C) 2009 Amrita Vishwa Vidyapeetham, Amritapuri.
#                                       (http://www.amrita.edu)
#    ***************************************************************************
#    This file is part of the Amrita ITEWS distribution.
#    Amrita ITEWS is free software; you can redistribute it and/or modify it 
#    under the terms of the GNU General Public License (version 2) as published
#    by the Free Software Foundation AND MODIFIED BY the Amrita ITEWS exception.
#    ***NOTE*** The exception to the GPL is included to allow you to distribute
#    a combined work that includes Amrita ITEWS without being obliged to provide
#    the source code for proprietary components outside of the Amrita ITEWS
#    software. Amrita ITEWS is distributed in the hope that it will be useful, 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
#    Public License for more details. You should have received a copy of the GNU
#    General Public License and the Amrita ITEWS license exception along with 
#    Amrita ITEWS if not then it can be viewed here: 
#
#
#    Documentation, latest information, license and contact details are at:
#    http://itews.amrita.ac.in/
#
#
#    Amrita ITEWS source code can be found at:
#    http://code.google.com/p/itews
#
#
#    The initial code-base of Amrita ITEWS was developed by Amrita Vishwa 
#    Vidyapeetham as part of the project titled,"Intelligent & Interactive 
#    Telematics using Emerging Wireless Technologies for Transport Systems 
#    (ITEWS)" sponsored by Technology Information Forecasting and Assessment 
#    Council (TIFAC), India.
#
#===============================================================================#

#export RUN_FROM = RAM
export RUN_FROM = FLASH
export BSP = lpc2148_aam
#export BSP = lpc2148_edu_board
# Compiler Flags.
export CC = arm-elf-gcc
export LD = arm-elf-ld
export CFLAGS = -Wall -g -mlittle-endian -mcpu=arm7tdmi -mthumb-interwork -DRUN_FROM_$(RUN_FROM)

# Platform Flags.
export PLATFORM = lpc21xx
export UT_PLATFORM = lpc21xx

# Build Directory Flags.
BUILD_DIR = build/$(PLATFORM)
PLATFORM_DIR = platform/$(PLATFORM)
UT_PLATFORM_DIR = platform/$(PLATFORM)/ut

# Platform Independant Sources and Objects Files.
SRC = ./*.c
OBJS = $(patsubst %.c,%.o,$(wildcard $(SRC)))

# Include Header Directory Flags.
INC = -I. -Iinclude -I../../eventq/src
PLATFORM_INC = -I$(PLATFORM_DIR)
UT_PLATFORM_INC = -I$(UT_PLATFORM_DIR) 

# Default Module Make.
all: default

# Compiling and generating  Test Programs.
test: default
    $(MAKE) -C $(PLATFORM_DIR) $@
    $(BUILD_DIR)/$(PLATFORM)_ut.exe 3   

# Compiling & LInking Module Source.
default: $(OBJS)
    $(MAKE) -C $(PLATFORM_DIR) $(PLATFORM)  # Compile Platform Specific Code.
    $(MAKE) -C uip default  # Compile uip code  
    
# Generate Documentations.  
doc:
    doxygen ../doxygen-config
    
# Display Help File.
help:
    cat Readme.txt  

#Source File Compilations.  
%.o: %.c
    @echo 'Building file: $<'
    @echo 'Invoking: GCC C Compiler'
    @echo $(CC) $(CFLAGS) $(INC) $(PLATFORM_INC) -c -o$@ $<
    @$(CC) $(CFLAGS) $(INC) $(PLATFORM_INC) -c -o$@ $<
    @echo 'Finished building: $<'
    @echo ' '

# Cleanup all Directories.  
clean: 
    $(RM) *.o
    $(RM) $(UT_PLATFORM_DIR)/*.o
    $(RM) -r build/doc/*
    $(MAKE) -C $(PLATFORM_DIR) $@
    $(MAKE) -C uip $@   

        